﻿using IQKS.AWP.BusinessAccessLayer;
using System;
using System.Configuration;
using System.Data;
using System.Web.UI.WebControls;

public partial class Dashboard : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblHeadmsg.Visible = false;
        if (!IsPostBack)
        {
            //Guid gudUserID = new Guid("8B551132-48EC-43DE-9C9E-1D389A8EBA99");     

            GetData(CommonUtility.GetLoggedOnUserId());
            GetDataPaymentStatus(CommonUtility.GetLoggedOnUserId());
        }
    }

    private void GetData(Guid UserId)
    {
        DataSet objDs;
        string strUserRole = CommonUtility.GetCurrentUserRole();
        objDs = new UserMasterBAL().GetStatusDashboard(UserId);

        if (strUserRole.Trim().Length > 0)
        {
            if (strUserRole == "CANM" || strUserRole == "CANB" || strUserRole == "CANR")
            {
                gvCandidateDetails.DataSource = objDs;
                gvCandidateDetails.DataBind();
                lblHeadmsg.Visible = false;
                DataSet objDsDesireAttribute = new UserMasterBAL().GetDesiredAttributesDoc(UserId);
                gvDesiredAttributes.DataSource = objDsDesireAttribute;
                gvDesiredAttributes.DataBind();
            }
            else
            {
                gvRegistrationStatusDashboard.DataSource = objDs;
                gvRegistrationStatusDashboard.DataBind();


                lblHeadmsg.Visible = true;
                lblHeadmsg.Text = "Workflow Dashboard - Level 1";
            }
            if (strUserRole == "RARL")
            {
                DataSet dSet = new UserMasterBAL().GetAssessorCalenderDashboard(UserId);
                if (dSet != null && dSet.Tables.Count > 0 && dSet.Tables[0] != null)
                    lblgvAssessorCalenderWithCandidate.Visible = false;
                gvAssessorCalenderWithCandidate.DataSource = dSet.Tables[0];
                gvAssessorCalenderWithCandidate.DataBind();

                gvPaymentConfirmation.DataSource = dSet.Tables[1];
                gvPaymentConfirmation.DataBind();
                if (dSet.Tables[1] != null && dSet.Tables[1].Rows.Count > 0)
                    lblPaymentConfirmation.Visible = true;
            }
            else
            {
                lblgvAssessorCalenderWithCandidate.Visible = false;
                gvAssessorCalenderWithCandidate.Visible = false;
            }

            if (strUserRole == "IQKSAD" || strUserRole == "IQKSMG" || strUserRole == "SU")
            {
                DataSet dSet = new UserMasterBAL().GetAssessorDaysForAdmin();
                if (dSet != null && dSet.Tables[0] != null && dSet.Tables.Count > 0)
                {
                    lblAssessorBookedForAdmin.Visible = true;
                    gvAssessorBookedForAdmin.Visible = true;

                    gvAssessorBookedForAdmin.DataSource = dSet.Tables[0];
                    gvAssessorBookedForAdmin.DataBind();

                }
                DataSet dSet1 = new UserMasterBAL().GetAssessorCalenderDashboardForAdmin(UserId);
                gvPaymentConfirmation.DataSource = dSet1.Tables[0];
                gvPaymentConfirmation.DataBind();
                if (dSet1.Tables[0] != null && dSet1.Tables[0].Rows.Count > 0)
                    lblPaymentConfirmation.Visible = true;
            }
            else if (strUserRole == "RD")
            {
                DataSet dSet = new UserMasterBAL().GetAssessorDaysForRd(CommonUtility.GetLoggedOnUserId());
                if (dSet != null && dSet.Tables[0] != null && dSet.Tables.Count > 0)
                {
                    lblAssessorBookedForAdmin.Visible = true;
                    gvAssessorBookedForAdmin.Visible = true;

                    gvAssessorBookedForAdmin.DataSource = dSet.Tables[0];
                    gvAssessorBookedForAdmin.DataBind();

                }
            }
        }
    }
    public string GetDesiredAttributesDownload(object objProposalDocumentFile)
    {
        string strPathProDoc = string.Empty;
        strPathProDoc = Convert.ToString(ConfigurationSettings.AppSettings["DownLoadPath"]) + Convert.ToString(objProposalDocumentFile);
        strPathProDoc = "javascript:onClickLinkDesireAttribute('" + strPathProDoc.Replace("~", "..") + "')";
        return strPathProDoc;
    }

    public string GetBriefUrl(object objCandidateType, object objBriefID, object objAccrediationComplete, object IsActive, object objCandidateID)
    {
        string strPath = string.Empty;
        if (Convert.ToBoolean(objAccrediationComplete) == true)
        {
            strPath = "~/Candidate/AccreditationCandidateCertificatePDF.aspx?CandidateID=" + Convert.ToString(objCandidateID);
        }
        else
        {
            if (Convert.ToBoolean(IsActive) == false)
            {
                strPath = "";
            }
            else
            {

                if (Convert.ToString(objCandidateType) == "CANM")
                {
                    strPath = "~/Candidate/CandidateBriefDetailsm.aspx?briefid=" + CommonUtility.Encrypt(Convert.ToString(objBriefID), true);
                }
                else if (Convert.ToString(objCandidateType) == "CANR")
                {
                    strPath = "~/Candidate/CandidateBriefDetails.aspx?briefid=" + CommonUtility.Encrypt(Convert.ToString(objBriefID), true);
                }
                else if (Convert.ToString(objCandidateType) == "CANB")
                {
                    strPath = "~/Candidate/CandidateBriefDetails.aspx?briefid=" + CommonUtility.Encrypt(Convert.ToString(objBriefID), true);
                }
            }
        }
        return strPath;
    }


    private void GetDataPaymentStatus(Guid UserId)
    {
        DataSet objDs;
        string strUserRole = CommonUtility.GetCurrentUserRole();
        objDs = new PaymentInvoiceBAL().GetPaymentStatusDashboardUserWise(UserId);
        if (strUserRole == "IQKSAD" || strUserRole == "IQKSMG" || strUserRole == "AD" || strUserRole == "RAM" || strUserRole == "RARL" || strUserRole == "IE")
        {
            gvPaymentStatus.DataSource = objDs;
            gvPaymentStatus.DataBind();
        }
        else
        {

        }

    }

    protected void gvRegistrationStatusDashboard_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvCandidateDetails.PageIndex = e.NewPageIndex;
        gvRegistrationStatusDashboard.PageIndex = e.NewPageIndex;
        GetData(CommonUtility.GetLoggedOnUserId());
    }

    protected void gvRegistrationStatusDashboard_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Session["StatusCode"] = e.CommandArgument.ToString();
        if (e.CommandName == "Details")
        {
            Session["StatusID"] = e.CommandArgument.ToString();
            if (e.CommandArgument.ToString() == "0")
            {
                Response.Redirect("~/home/CandidateAccrediationDetails.aspx");
            }
            else
            {
                Response.Redirect("~/home/CandidateStatus.aspx");
            }
        }
    }


    protected void gvPaymentStatus_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Details")
        {
            Session["PaymentStatusID"] = e.CommandArgument.ToString();

            Response.Redirect("~/home/PaymentStatus.aspx");
        }

    }

    protected void gvCandidateDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //if (e.CommandName == "Details")
        //{
        //    string strBriefID;
        //    strBriefID = e.CommandArgument.ToString();
        //    Response.Redirect("/Candidate/CandidateBriefDetails.aspx?briefid=" + strBriefID);
        //}

    }

    protected void gvAssessorCalenderWithCandidate_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToString(((System.Data.DataRowView)(e.Row.DataItem)).Row["AlternateRow"]) == "0")
            {
                e.Row.Style.Add("background-color", "lightgreen");
                e.Row.Cells[1].Style.Add("color", "black");
                e.Row.Cells[2].Style.Add("color", "black");
            }
        }
    }
    protected void btnPaymentRec_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(hdnPaymentCandidateID.Value) != "" && hdnPaymentCandidateID.Value != "0")
        {
            new UserMasterBAL().UpdateCandidateAssessorPayment(CommonUtility.GetLoggedOnUserId(), Convert.ToInt32(hdnPaymentCandidateID.Value));
            string strUserRole = CommonUtility.GetCurrentUserRole();
            if (strUserRole == "RARL")
            {
                DataSet dSet = new UserMasterBAL().GetAssessorCalenderDashboard(CommonUtility.GetLoggedOnUserId());
                gvPaymentConfirmation.DataSource = dSet.Tables[1];
                gvPaymentConfirmation.DataBind();
                if (dSet.Tables[1] != null && dSet.Tables[1].Rows.Count > 0)
                    lblPaymentConfirmation.Visible = true;
                else
                    lblPaymentConfirmation.Visible = false;
            }
            if (strUserRole == "IQKSAD" || strUserRole == "IQKSMG" || strUserRole == "SU")
            {   
                DataSet dSet1 = new UserMasterBAL().GetAssessorCalenderDashboardForAdmin(CommonUtility.GetLoggedOnUserId());
                gvPaymentConfirmation.DataSource = dSet1.Tables[0];
                gvPaymentConfirmation.DataBind();
                if (dSet1.Tables[0] != null && dSet1.Tables[0].Rows.Count > 0)
                    lblPaymentConfirmation.Visible = true;
            }
        }
    }

    protected void gvPaymentConfirmation_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Button btn = (Button)e.Row.FindControl("btnPaymentRec");
            btn.OnClientClick = "javascript:return fn_ConfirmForPaymentReceive(" + e.Row.Cells[0].Text + ");";
            e.Row.Cells[0].Style.Add("display", "none");
        }
        else if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Style.Add("display", "none");
        }
    }
    protected void gvAssessorBookedForAdmin_RowDataBound(object sender, GridViewRowEventArgs e)
    {

    }

    protected void gvAssessorCalenderWithCandidate_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataSet dSet = new UserMasterBAL().GetAssessorCalenderDashboard(CommonUtility.GetLoggedOnUserId());
        gvAssessorCalenderWithCandidate.DataSource = dSet.Tables[0];
        gvAssessorCalenderWithCandidate.PageIndex = e.NewPageIndex;
        gvAssessorCalenderWithCandidate.DataBind();
        //gvRegistrationStatusDashboard.PageIndex = e.NewPageIndex;
        // GetData(CommonUtility.GetLoggedOnUserId());
    }

    protected void gvAssessorCalenderWithCandidate_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "CalendarDetails")
        {
            if (e.CommandArgument.ToString() != null && e.CommandArgument.ToString() != "")
            {
                string[] arg = new string[2];
                arg = e.CommandArgument.ToString().Split(';');
                Session["CandidateID"] = arg[0];
                Session["CandidateBriefID"] = arg[1];
                Session["Candidate"] = arg[2];
                Session["BriefID"] = arg[3];
                Response.Redirect("~/Assessor/CandidateCalendarView.aspx");
            }
        }
    }
}